﻿using System;
using IotWeek2Day9.Models;
using Microsoft.EntityFrameworkCore;

namespace IotWeek2Day9.EFCore
{
    /// <summary>
    /// 数据库的上下文
    /// </summary>
    public class EmpDbContext:DbContext
    {
        public EmpDbContext(DbContextOptions<EmpDbContext> options):base(options)
        {

        }

        public DbSet<Emp>  Emps { get; set; }
        public DbSet<Item>   Items { get; set; }


        //数据播种（直接在C#中去给数据表添加初始数据）
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Emp>().HasData(
                  new Emp { EId=1, EName= "张晓辉" },
                  new Emp { EId=2, EName= "石春光" },
                  new Emp { EId=3, EName= "李小伟" }
                );

            base.OnModelCreating(modelBuilder);
        }
    }
}
